#include "StdAfx.h"
#include "TLUT.h"

TWLLUT::TWLLUT(void):
minInputValue(-100000),
maxInputValue(100000),
isReflected(false){
}

TWLLUT::~TWLLUT(void)
{
}

void TWLLUT::doWLLUT( int maxValue, int w, int l){
	LUT.resize(maxInputValue - minInputValue + 1);
	int maxValueReflect = maxValue;	
	int color;
	int left = l - w / 2;
	int right = l + w / 2; 
	for(int i = minInputValue; i <= maxInputValue; i++){	
		if(right - left == 0){
			color = 0;
		}else{
			if(i >= left && i <= right)
				color = maxValue * ((float)i - (float)left) / ((float)right - (float)left);
			if(i < left)
				color = 0;
			if(i > right)
				color = maxValue;	
		}
		if(isReflected)
			LUT[i - minInputValue ] = maxValue - color;
		else
			LUT[i - minInputValue ] = color;	
	}
}

int TWLLUT::getOutputValue( int inputValue){
	if(inputValue < minInputValue)
		return LUT[0];
	if(inputValue > maxInputValue)
		return LUT[maxInputValue - minInputValue];
	return LUT[inputValue - minInputValue];
}

void TWLLUT::setisReflected(BOOLEAN isReflected )
{
	this->isReflected = isReflected;
}

bool TWLLUT::operator==( const TWLLUT& other ) const
{	

	if(this->LUT == other.LUT )
		return true;
	else
		return false;
}

bool TWLLUT::operator!=( const TWLLUT& other ) const
{
	return !operator==(other); 
}